package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.impl.DishServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO) {
        dishService.addDish(dishDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation("菜品列表")
    public Result<PageResult> dishLish(DishPageQueryDTO dishPageQueryDTO) {
        PageResult list = dishService.dishList(dishPageQueryDTO);
        return Result.success(list);
    }
    @GetMapping("/list")
    @ApiOperation("菜品列表")
    public Result<PageResult> dishList(Integer categoryId) {
        DishPageQueryDTO dishPageQueryDTO1 = new DishPageQueryDTO();
        dishPageQueryDTO1.setPage(1);
        dishPageQueryDTO1.setPageSize(100);
        dishPageQueryDTO1.setCategoryId(categoryId);

        PageResult list = dishService.dishList(dishPageQueryDTO1);
        return Result.success(list);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售、停售")
    public Result setStatus(Integer id, @PathVariable Short status) {
        dishService.setStatus(id, status);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation("批量删除")
    public Result deleteDishByIds(String ids) {
        dishService.deleteDishByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("获取菜品")
    public Result<Dish> getDish(@PathVariable Integer id) {
        Dish dish = dishService.getDish(id);
        return Result.success(dish);
    }

    @PutMapping
    @ApiOperation("更新菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO) {
        dishService.updateDish(dishDTO);
        return Result.success();
    }
}